﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CodeArt.SharePoint.SmartQuery
{
    using System.Web;
    using Microsoft.SharePoint.Utilities;
    using System.Threading;
    internal class ResourcesHelper
    {
        const string resource = "CodeArt.SharePoint.SmartQuery";

        public static string GetResource(string key)
        {
            return SPUtility.GetLocalizedString("$Resources:," + key, resource, (uint)Thread.CurrentThread.CurrentUICulture.LCID);
        }     

        public static string GetResourceString(string key)
        {
            return GetResourceString(key, null);
        }

        public static string GetResourceString(string key, string defaultText)
        {
            string value = string.Empty;
            try
            {
                value = GetResource(key);
            }
            catch {}

            if(String.IsNullOrEmpty(defaultText))
                return value;

            if (String.IsNullOrEmpty(value))
            {
                return defaultText;
            }
            else if (value.StartsWith("$Resources:"))
                return defaultText;
            else
                return value; 
        }
    }
}
